/*
 * Created on Jan 10, 2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package littlecyberwar.control;

import java.io.*;

import littlecyberwar.model.Command;
import littlecyberwar.model.ModelChangeFacade;

/**
 * @author Milton  Soong
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class FileCmdHandler {
	ObjectInputStream oi;
	ModelChangeFacade mcf;
	
	public FileCmdHandler (File fIn, ModelChangeFacade mcfIn ) {
		mcf = mcfIn;
		try {
			FileInputStream fi = new FileInputStream( fIn );
			oi = new ObjectInputStream( fi );
		} catch (IOException ex) {
			ex.printStackTrace();
		}		 	
	}
	
	public void close() {
		try {
			oi.close();
		}catch (IOException ex) {
			ex.printStackTrace();
		}		
	}
	
	/**
	 * Returns a non-zero status if there are no more commands
	 *
	 */
	public int processOneCmd() {
		int stat=0;
		try {		
			Command cmd = (Command)oi.readObject();
			mcf.addCmd(cmd);
			
		}catch (EOFException ex){
			// there are no more bytes
			stat=1;
		}catch (Exception ex) {
			ex.printStackTrace();
		}
		return (stat);
	}
	
	public void processAllCmd() {
		
	
	}
}
